<template>
	<view class="page">
		<image src="../../static/register/top2.jpg" mode="widthFix" class="top" />
		<view class="location-container">
			<view class="left">
				<image src="../../static/register/location.png" mode="widthFix" class="location"></image>
				<text>代驾服务地点</text>
			</view>
			<view class="right">{{cityName}}</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">入驻条件</text>
			</view>
			<view class="list">
				<view class="item">
					<text>1.</text>
					三年安全驾驶经验；
				</view>
				<view class="item">
					<text>2.</text>
					年龄23~55周岁；
				</view>
				<view class="item">
					<text>3.</text>
					无违法犯罪记录、无精神病史、无吸毒史，以及平台认为不适合代驾的其他历史证明；
				</view>
				<view class="item">
					<text>4.</text>
					有熟练驾车经验；
				</view>
				<view class="item">
					<text>5.</text>
					身体健康，无肢体残疾和大面积纹身；
				</view>
				<view class="item">
					<text>6.</text>
					需要提供身份证、驾驶证、直系亲属联系方式，并保存前述材料的真实合法性；
				</view>
			</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">入驻流程</text>
			</view>
			<view class="list">
				<view class="complex-item">
					<view class="left">01</view>
					<view class="right">
						<text class="item-title">在线注册账号</text>
						<text class="item-desc">在小程序完成注册</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">02</view>
					<view class="right">
						<text class="item-title">司机信息填写</text>
						<text class="item-desc">按照流程提交本人身份证、驾驶证</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">03</view>
					<view class="right">
						<text class="item-title">证件资料审核</text>
						<text class="item-desc">对提交证件进行审核</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">04</view>
					<view class="right">
						<text class="item-title">签署合同</text>
						<text class="item-desc">收到邮寄的合同后必须本人签署并寄回</text>
					</view>
				</view>
			</view>
		</view>
		<button class="btn"  open-type="getPhoneNumber"  @getphonenumber="wxRegister" >司机注册</button> 
		<!-- <button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhone" >微信注册</button> -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
var QQMapWX = require('../../lib/qqmap-wx-jssdk.min.js');
var qqmapsdk;
export default {
	data() {
		return {
			code: null,
			cityName:"成都"
		};
	},
	//当页面加载就自行
	onLoad() {
		//初始化地图相关
		this.initMap();
		//定位
		this.getLocation();
	},
	methods: {
		initMap(){
			qqmapsdk = new QQMapWX({
			    key: this.Consts.QQMAP_KEY // 必填
			}); 
		},
		//腾讯地图，地址解析
		reverseGeocoder(location){
			let _this = this;
			qqmapsdk.reverseGeocoder({
				location: location,
				success:function(res){
					console.log("获取到地址 ",res);
					let city = res.result.address_component.city;
					_this.cityName = city;
				}
			});
		},
		//获取坐标位子
		getLocation(){

			//VUE对象
			let _this = this;
			
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					console.log("获取到经纬度",res);
					let location = {
					  latitude: res.latitude,
					  longitude: res.longitude
					}
					_this.reverseGeocoder(location);
				},fail: function(error) {
					uni.showToast({
						icon:"error",
						title:"定位失败"
					})
			    }
			});

		},
		//使用微信注册
		wxRegister(e){
			if(!e.detail.code){
				uni.showToast({
					title:"授权失败",icon:"error"
				})
				return;
			}
			
			let _this = this;
			
			wx.login({
			  success (res) {
			    if (res.code) {
			      //发送注册请求  "http://127.0.0.1:10010/drive/driver/app/driver/wx/register"
				 let param = {
					 //微信登录的Code
					 wechatCode:res.code,	
					 //获取手机号的Code
					 // phoneCode:e.detail.code
				 }
				  _this.post("/driver/app/driver/wxRegister",param,(res)=>{
					  const {success,message} = res.data;
					  if(success){
						  uni.showToast({
						  	title:"注册成功",icon:"success"
						  })
						  //跳回登录页面
						  setTimeout(()=>{
							  uni.navigateBack();
						  },2000)
					  }else{
						  uni.showToast({
						  	title:message,icon:"error"
						  })
					  }
				  });
			    } else {
			      uni.showToast({
			      	title:"注册失败",icon:"error"
			      })
			    }
			  }
			})
		},
	}
};
</script>

<style lang="less">
@import url('register.less');
</style>
